import java.io.IOException;
import java.util.Arrays;

public class Euler022 {

	public static void main(String[] args) throws IOException {
		final long start = System.currentTimeMillis();
		final String delimeter = ",";
		final String data = Common.readFile("p022_names.txt");
		String[] splitData = data.split(delimeter);
		Arrays.sort(splitData);
		int sum = 0;
		int sum_temp;
		for (int i = splitData.length-1; i >= 0; i--) {
			sum_temp = 0;
//			for(char c : splitData[i].toCharArray()) {
//				sum_temp += getChar(c);
//			}
			for(int c = splitData[i].length() - 1; c >= 0; c --) {
				char ci = splitData[i].charAt(c);
				if(ci > 64 ) sum_temp += ci - 64;
			}
			sum += sum_temp * (i+1);
		}
		System.out.println(sum);
		System.out.println(System.currentTimeMillis()-start);
		for(char c : splitData[0].toCharArray()) {
			System.out.println(getChar(c));
//			sum_temp = sum_temp + getChar(c);
		}
		
		for(int i = splitData[0].length()-1; i >=0; i--){
			System.out.println(getChar(splitData[0].charAt(i)));
//			sum_temp = sum_temp + getChar(c);
		}
		final String data_test = "ANANA";
		for(int i = data_test.length()-1; i >=0; i--){
			System.out.println(getChar(splitData[0].charAt(i)));
//			sum_temp = sum_temp + getChar(c);
		}
	}
	
	private static final int getChar(final char c) {
		// Well, lazy to handle with double quote ""
		return c - 64;
	}
}
